package org.jeecg.modules.carLedger.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.carLedger.entity.CarLedger;

import java.util.List;
import java.util.Map;

/**
 * @Description: 进出厂车辆电子台账
 * @Author: jeecg-boot
 * @Date:   2024-07-23
 * @Version: V1.0
 */
public interface CarLedgerMapper extends BaseMapper<CarLedger> {

    @Select("select fleet, count(*) as count from car_ledger " +
            "where create_time between #{start} and #{end} " +
            "group by fleet order by count desc limit 3")
    List<Map<String, Object>> getTopThreeFleets(@Param("start") String start, @Param("end") String end);

    @Select("select goods, count(*) as count from car_ledger " +
            "where create_time between #{start} and #{end} " +
            "group by goods order by count desc limit 3")
    List<Map<String, Object>> getTopThreeGoods(@Param("start") String start, @Param("end") String end);

    @Select("SELECT COUNT(*) AS today_count FROM car_ledger " +
            "WHERE create_time >= CURRENT_DATE AND create_time < CURRENT_DATE + INTERVAL 1 DAY;")
    int getTodayCount();

    @Select("SELECT COUNT(*) AS today_count FROM car_ledger " +
            "WHERE entry_time is not null AND create_time >= DATE_SUB(CURDATE(), INTERVAL 1 DAY) AND create_time < CURDATE();")
    int getVehiclePassRecordsNum();

    @Select("SELECT COUNT(*) AS month_count FROM car_ledger " +
            "WHERE YEAR(create_time) = YEAR(CURRENT_DATE) AND MONTH(create_time) = MONTH(CURRENT_DATE);")
    int getMonthCount();

    @Select("select fleet, count(*) as count from car_ledger " +
            "where create_time between #{start} and #{end} and leading_enterprise = 1 " +
            "group by fleet order by count desc limit 3")
    List<Map<String, Object>> getTopThreeFleetsLeading(@Param("start") String start, @Param("end") String end);

    @Select("select goods, count(*) as count from car_ledger " +
            "where create_time between #{start} and #{end} and leading_enterprise = 1 " +
            "group by goods order by count desc limit 3")
    List<Map<String, Object>> getTopThreeGoodsLeading(@Param("start") String start, @Param("end") String end);

}
